package main;

import plugins.IPlugin;
import messages.IMessage;

/**
 * The Class defines all methods the plugins can use
 * to communicate.
 * 
 * @author daishy
 * @date 27.03.2008 12:10:09
 *
 */
public interface IMessagedispatcher
{
	/**
	 * This exception is used if something went wront during the dispatching
	 * or the target can not be found.
	 * 
	 * @author daishy
	 * @date 28.03.2008 17:54:33
	 *
	 */
	public static class MessagedispatcherException extends Exception
	{
		/**
		 * Default Serial-Ver-ID
		 */
		private static final long serialVersionUID = 1L;

		/**
		 * CTor
		 * @param msg The message of the exception
		 */
		public MessagedispatcherException(String msg) {
			super(msg);
		}	
	}
	
	/**
	 * This method dispatches the request to the appropriate Plugin and
	 * does not return until a response is filled.
	 * 
	 * @param request The request to process
	 * @throws MessagedispatcherException If target cant be found etc.
	 */
	public void sendRequest(messages.IRequest request) throws MessagedispatcherException;
	
	/**
	 * This method dispatches a message to all who have interest in it.
	 * It will not wait until the message is completly dispatched
	 * 
	 * @param message The message to send
	 * @throws MessagedispatcherException If something went wrong during the dispatching
	 */
	public void sendMessage(IMessage message) throws MessagedispatcherException;
	
	public void sendMessage(String group, IMessage message) throws MessagedispatcherException;
	
	public void registerGroup(String group) throws MessagedispatcherException;
	
	public void unregisterGroup(String group) throws MessagedispatcherException;
	
	public void subscribeGroup(IPlugin plugin, String group) throws MessagedispatcherException;
	
	public void unsubscripe(IPlugin plugin, String group) throws MessagedispatcherException;
}
